home *** CD-ROM | disk | FTP | other *** search
- ; $Id: d_animate.pro,v 1.16 1997/04/18 01:45:37 tremblay Exp $
- ;
- ; Copyright (c) 1997, Research Systems, Inc. All rights reserved.
- ; Unauthorized reproduction prohibited.
- ;
- ;+
- ; FILE:
- ; cfd.pro
- ;
- ; CALLING SEQUENCE: cfd
- ;
- ; PURPOSE:
- ; Display an animation of the pressure field around a sphere.
- ;
- ; MAJOR TOPICS: Animation and widgets
- ;
- ; CATEGORY:
- ; IDL 4.0
- ;
- ; INTERNAL FUNCTIONS and PROCEDURES:
- ; pro d_cfd - Call the cfd animation.
- ; pro d_tides - Call the tides animation.
- ; pro d_gated - Call the gated blood animation.
- ; pro Animate_demo_Event - Event handler
- ; pro Animate_demo_Cleanup - Cleanup
- ; pro cfd - Main procedure
- ;
- ; EXTERNAL FUNCTIONS, PROCEDURES, and FILES:
- ; pro CW_ANIMATE: - Animation tool routine
- ; pro CW_ANIMATE_INIT: - Animation tool routine
- ; pro CW_ANIMATE_LOAD: - Animation tool routine
- ; pro CW_ANIMATE_RUN: - Animation tool routine
- ; fun getTips - Get the tip text
- ; pro widTips - Create the widget text for tips
- ; pro sizeTips - Size the widget text for tips
- ;
- ; REFERENCE: IDL Reference Guide, IDL User's Guide
- ;
- ; NAMED STRUCTURES:
- ; none.
- ;
- ; COMMON BLOCS:
- ; none.
- ;
- ; MODIFICATION HISTORY:
- ;
- ;-
- ;---------------------------------------------------------
- ;
- ; PURPOSE : Call for the pressure field animation.
- ;
- pro d_cfd, $
- GROUP = group, $ ; IN: (opt) group identifier
- APPTLB = wTopBase ; OUT: (opt) TLB of this application
-
- d_animate, "cfd", "Pressure Field Animation", $
- NFRAMES=16, NCOLORS=160, $
- GROUP=group, APPTLB = wTopBase
- end ;cfd
-
- ;---------------------------------------------------------
- ;
- ; PURPOSE : Call for the oceanic tides animation.
- ;
- pro d_tides, $
- GROUP = group, $ ; IN: (opt) group identifier
- APPTLB = wTopBase ; OUT: (opt) TLB of this application
-
- d_animate, "tides", "Oceanic Tides", $
- NFRAMES=12, NCOLORS=150, $
- GROUP=group, APPTLB = wTopBase
- end ;cfd
-
- ;---------------------------------------------------------
- ;
- ; PURPOSE : Call for the gated blood pool animation.
- ;
- pro d_gated, $
- GROUP = group, $ ; IN: (opt) group identifier
- APPTLB = wTopBase ; OUT: (opt) TLB of this application
-
- ; If gated data file is NOT compressed:
- d_animate, "gated", "Gated Blood Pool", $
- UNCOMPRESSED = [128, 64], $
- COLOR_TABLE_INDEX = 3, $
- NFRAMES=15, NCOLORS=225, GROUP=group, APPTLB = wTopBase, /ZOOM
-
- ; If we use a gif file:
- ; animate_demo, "gated", "Gated Blood Pool", $
- ; NFRAMES=15, NCOLORS=225, GROUP=group, APPTLB = wTopBase, /ZOOM
-
- end ;cfd
-
- ;---------------------------------------------------------
- ;
- ; PURPOSE : event handler
- ;
- pro Animate_Demo_Event, $
- sEvent ; IN: event structure
-
- if (TAG_NAMES(sEvent, /STRUCTURE_NAME) EQ $
- 'WIDGET_KILL_REQUEST') then begin
- WIDGET_CONTROL, sEvent.top, /DESTROY
- RETURN
- endif
-
- WIDGET_CONTROL, sEvent.id, GET_UVALUE= uValue
-
- case uValue of
- ; Quit this application (end animation button).
- ;
- 0 : begin
- WIDGET_CONTROL, sEvent.top, /DESTROY
- RETURN
- end
-
- ; Quit this application (menu bar).
- ;
- 1 : begin
- WIDGET_CONTROL, sEvent.top, /DESTROY
- RETURN
- end
-
- 2 : begin
- XLOADCT, GROUP=sEvent.top
- RETURN
- end
-
- ; Display the information file.
- ;
- 3 : begin
- ; Verify that there is only one instance of XDisplayFile
- ;
- if (Xregistered('XDisplayFile') NE 0) then RETURN
- Widget_Control, sEvent.top, GET_UVALUE = sInfo
- XDisplayFile, filepath(sInfo.DemoName + ".txt", $
- SUBDIR=['examples','demo','demotext']), $
- DONE_BUTTON='Done', $
- TITLE= sInfo.Title, $
- GROUP=sEvent.top, WIDTH=55, HEIGHT=14
- end
-
- endcase
- end ; of Animate_Demo_EVENT
-
- ;---------------------------------------------------------
- ;
- ; PURPOSE : Cleanup procedure
- ;
- pro Animate_Demo_Cleanup, wTopBase
-
- ; Get the info structure saved in the window's user value.
- ;
- WIDGET_CONTROL, wTopBase, GET_UVALUE=sInfo, /NO_COPY
-
- ; Restore the previous color table.
- ;
- TVLCT, sInfo.colorTable
-
- ; Map the group leader bvase if it exists.
- ;
- if (WIDGET_INFO(sInfo.groupBase, /VALID_ID)) then $
- WIDGET_CONTROL, sInfo.groupBase, /MAP
-
- end
-
- ;---------------------------------------------------------
- ;
- PRO d_animate, Demoname, Title, $
- NFrames = Nframes, $
- NCOLORS=ncolors, $ ;# of colors required, if omitted !d.n_colors
- UNCOMPRESSED = uncompressed, $ ;If data file isn't in GIF format,
- ;this contains the dimensions of the images.
- ZOOM=zoom, $ ;TRUE to zoom up if screen is large
- COLOR_TABLE_INDEX = colortb_index, $ ; If set, load this color tbl
- GROUP = group, $ ; IN: (opt) group identifier
- APPTLB = wTopBase ; OUT: (opt) TLB of this application
-
- ; tstart = systime(1)
- if (n_elements(group) NE 0) then groupBase = group $
- else groupBase = 0L
-
- ; Initialize the device.
- ;
- if (((!D.Name EQ 'X') OR (!D.NAME EQ 'MacOS')) AND $
- (!D.N_Colors GE 256L)) then DEVICE, PSEUDO_COLOR=8
- DEVICE, Decomposed=0, Bypass_Translation=0
- DEVICE, GET_SCREEN_SIZE = scrsize
-
- drawbase = startmes(GROUP=groupbase) ; Create the starting up message.
-
- ; Determine the input file name:
- if keyword_set(uncompressed) then filename = DemoName + '.dat' $
- else filename = DemoName + '.gif'
- Filename = filepath(filename, SUBDIR=['examples', 'demo', 'demodata'])
-
- openr, lun, /GET_LUN, Filename, ERROR=i ;See if file is readable
- if i lt 0 then begin
- result = DIALOG_MESSAGE(["Can't read Data file:", filename], /ERROR)
- if groupBase ne 0 then WIDGET_CONTROL, groupBase, /MAP
- WIDGET_CONTROL, drawbase, /DESTROY ; Destroy the starting up window.
- RETURN
- endif
-
- ; Get the current color table. It will be restored when exiting.
- TVLCT, savedR, savedG, savedB, /GET
- colorTable = [[savedR],[savedG],[savedB]]
-
- if keyword_set(uncompressed) then begin
- Image = Bytarr(uncompressed(0), uncompressed(1), /NOZERO)
- readu, Lun, Image
- if n_elements(colortb_index) ne 0 then loadct, colortb_index, /SILENT
- ncolors = !d.table_size ;We've got the correct number of colors
- tvlct, Red, Green, Blue, /GET
- endif else begin
- read_gif, Filename, Image, Red, Green, Blue, /MULTIPLE ;Get the first image
- free_lun, lun
- endelse
-
- s = size(Image) ;Get dimensions of frame
- ImXSize = s(1) ;Window and file image size
- ImYSize = s(2)
-
-
- if keyword_set(ZOOM) then begin ;Rebin?
- DEVICE, GET_SCREEN=screenSize ;How large is the screen
-
- ; Try for approx 1/2 the vertical height of the screen
- zoomFactor = 0.666 * Float(screenSize) / s(1:2) ;Screensize / image size
- zoomFactor = FLOOR(min(zoomFactor)) > 1 ;Vertical zoom
- endif else zoomFactor = 1
-
- winxsize = zoomFactor * ImXSize
- winysize = zoomFactor * ImYSize
-
- sText = getTips(filepath(DemoName+'.tip', $
- SUBDIR=['examples','demo', 'demotext']) )
-
- if n_elements(ncolors) eq 0 then ncolors = !d.table_size ;Default = what we got
-
- if !d.table_size lt ncolors then $ ;Compress color tables?
- TVLCT, BYTSCL(red, MAX=ncolors-1), $
- BYTSCL(green, MAX=ncolors-1), $
- BYTSCL(Blue, MAX=ncolors-1) $
- else TVLCT, Red, Green, Blue ;The Demo's color table
-
- wTopBase = WIDGET_BASE(TITLE = Title, /COLUMN, $
- MBAR=barBase, $
- /TLB_KILL_REQUEST_EVENTS, $
- GROUP_LEADER=groupbase, $
- TLB_FRAME_ATTR=1, MAP=0)
-
- wFileButton = WIDGET_BUTTON(barBase, VALUE='File', $
- UVALUE='File', /MENU)
-
- wQuitButton = WIDGET_BUTTON(wFileButton, VALUE='Quit', $
- UVALUE=1)
-
- wViewButton = WIDGET_BUTTON(barBase, VALUE='View', $
- UVALUE='VIEW', /MENU)
-
- wColorButton = WIDGET_BUTTON(wViewButton, $
- VALUE='Colors...', $
- UVALUE=2)
-
- wHelpButton = WIDGET_BUTTON(barBase, VALUE='About', $
- UVALUE='HELP', /MENU, /HELP)
-
- wAboutButton = WIDGET_BUTTON(wHelpButton, $
- VALUE='About this animation', $
- UVALUE=3)
-
- animate = CW_ANIMATE(wTopBase, winxsize, $
- winysize, Nframes,$
- INFO_FILE=filepath(DemoName + '.txt', $
- SUBDIR=['examples','demo','demotext']))
-
- wStatusBase = WIDGET_BASE(animate, MAP=0, /ROW) ; text widget for tips.
-
- nWidgets = 2
- wText = LONARR(nWidgets)
- widTips, wStatusBase, sText.text, XSIZE=36, YSIZE=3, NWIDGETS=nWidgets, wText
-
- WIDGET_CONTROL, wTopBase, /REALIZE ; Realize the widget hierarchy.
-
- sizeTips, wTopBase, wText, wStatusBase ; Size the tips widgets.
-
-
- sInfo = { $ ; Create the info structure.
- DemoName : DemoName, $ ;our name
- Title : Title, $
- colorTable: colorTable, $ ; saved color table to restore
- groupBase: groupbase $ ; Base of Group Leader
- }
-
- WIDGET_CONTROL, wTopBase, SET_UVALUE=sInfo, /NO_COPY
- WIDGET_CONTROL, drawbase, /DESTROY ; Destroy the starting up window.
- WIDGET_CONTROL, wTopBase, map = 1 ; Map the top level base.
-
- for i = 0, Nframes-1 do begin ; Load the images.
- if i ne 0 then begin ;Read 2nd and following images
- if keyword_set(uncompressed) then readu, lun, Image $
- else read_gif, Filename, Image, Red, Green, Blue, /MULTIPLE
- endif
-
- if !d.table_size lt ncolors then $ ;Compress color tables?
- image = BYTSCL(image, TOP=!D.TABLE_SIZE-1, MAX=ncolors, MIN=0)
-
- if zoomFactor ne 1 then $ ;Zoom up?
- CW_ANIMATE_LOAD, animate, FRAME=i, $
- IMAGE= REBIN(Image, winxsize, winysize) $
- else CW_ANIMATE_LOAD, animate, FRAME=i, image= image
- endfor
-
- if keyword_set(uncompressed) then FREE_LUN, lun $
- else READ_GIF, /CLOSE ;Done w/ input file
-
- Image = 0 ;Free the space
-
- CW_ANIMATE_RUN, animate, 20 ; Run the animation...
-
- ; print, systime(1) - tstart, ' seconds'
-
- XMANAGER, DemoName, wTopBase, Event_Handler='animate_demo_Event', $
- Cleanup='animate_demo_Cleanup', /NO_BLOCK
- end ; animate_demo
-